package com.zjy.basic.controller;

import com.zjy.basic.exception.BusinessException;
import com.zjy.basic.service.VerifyCodeService;
import com.zjy.basic.util.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/verifyCode")
public class VerifyCodeController {

    @Autowired
    private VerifyCodeService verifyCodeService;

    @GetMapping("/image/{key}")
    public String getVerifyCode(@PathVariable("key") String key){
        return verifyCodeService.getImageCode(key);
    }

    @PostMapping("/smsCode")
    public AjaxResult getSmsCode(@RequestBody Map<String,String> map){
        try {
            verifyCodeService.getSmsCode(map);
            return new AjaxResult();
        } catch (BusinessException e) {
            e.printStackTrace();
            return new AjaxResult(false,e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            return new AjaxResult(false,"操作失败，请稍后再试");
        }
    }
    @PostMapping("/binderSmsCode")
    public AjaxResult getBinderSmsCode(@RequestBody Map<String,String> map){
        try {
            verifyCodeService.getBinderSmsCode(map);
            return new AjaxResult();
        } catch (BusinessException e) {
            e.printStackTrace();
            return new AjaxResult(false,e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            return new AjaxResult(false,"操作失败，请稍后再试");
        }
    }
}
